package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CollectRule;
import com.ruoyi.system.service.ICollectRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集规则Controller
 *
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/collectRule")
public class CollectRuleController extends BaseController
{
    @Resource
    private ICollectRuleService collectRuleService;

    /**
     * 查询采集规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:collectRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(CollectRule collectRule)
    {
        startPage();
        List<CollectRule> list = collectRuleService.selectCollectRuleList(collectRule);
        return getDataTable(list);
    }

    /**
     * 导出采集规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:collectRule:export')")
    @Log(title = "采集规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CollectRule collectRule)
    {
        List<CollectRule> list = collectRuleService.selectCollectRuleList(collectRule);
        ExcelUtil<CollectRule> util = new ExcelUtil<CollectRule>(CollectRule.class);
        util.exportExcel(response, list, "采集规则数据");
    }

    /**
     * 获取采集规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:collectRule:query')")
    @GetMapping(value = "/{collectId}")
    public AjaxResult getInfo(@PathVariable("collectId") Long collectId)
    {
        return success(collectRuleService.selectCollectRuleByCollectId(collectId));
    }

    /**
     * 新增采集规则
     */
    @PreAuthorize("@ss.hasPermi('system:collectRule:add')")
    @Log(title = "采集规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollectRule collectRule)
    {
        return toAjax(collectRuleService.insertCollectRule(collectRule));
    }

    /**
     * 修改采集规则
     */
    @PreAuthorize("@ss.hasPermi('system:collectRule:edit')")
    @Log(title = "采集规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollectRule collectRule)
    {
        return toAjax(collectRuleService.updateCollectRule(collectRule));
    }

    /**
     * 删除采集规则
     */
    @PreAuthorize("@ss.hasPermi('system:collectRule:remove')")
    @Log(title = "采集规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectIds}")
    public AjaxResult remove(@PathVariable Long[] collectIds)
    {
        return toAjax(collectRuleService.deleteCollectRuleByCollectIds(collectIds));
    }
}
